package com.carstop.model;

import javax.servlet.*;
import javax.servlet.http.*;
import org.json.JSONArray;
import org.json.JSONException;



import java.io.*;
import java.util.List;

public class CarStopServletFindStopAndroid extends HttpServlet {
    public void doGet(HttpServletRequest rq, HttpServletResponse rp) 
    				throws ServletException, IOException{
    	String city = rq.getParameter("city");
    	String city2 ="";
    	String CarStopJsonStr="";
    	if (city==null){
    		city="";	
    		
		}else {
    	city2 = new String(city.getBytes("ISO-8859-1"), "UTF-8");
    	
    	List<CarStopVO> carstoplist=null;
    	CarStopFindStopJsonHandler carstopJsonHandler = null;
    	rq.setCharacterEncoding("UTF-8");
    	CarStopDAO carstopdao = new CarStopDAO();           		
        	
        	carstoplist=carstopdao.getOneStop(city2);
        	
    		carstopJsonHandler =new CarStopFindStopJsonHandler();    	
    		CarStopJsonStr=carstopJsonHandler.toJSONArray(carstoplist).toString();
		}
    	


		
	       rp.setContentType("text/html; charset=utf-8");
	        PrintWriter out = rp.getWriter();
	        out.println(CarStopJsonStr); 
	        out.close();

    }
    
    public void doPost(HttpServletRequest rq, HttpServletResponse rp) 
    				throws ServletException, IOException{
    	String city = rq.getParameter("city");
    	String city2 ="";
    	String CarStopJsonStr="";
    	if (city==null){
    		city="";	
    		
		}else {
    	city2 = new String(city.getBytes("ISO-8859-1"), "UTF-8");
    	
    	List<CarStopVO> carstoplist=null;
    	CarStopFindStopJsonHandler carstopJsonHandler = null;
    	rq.setCharacterEncoding("UTF-8");
    	CarStopDAO carstopdao = new CarStopDAO();       	
    		
        	
        	carstoplist=carstopdao.getOneStop(city2);
        	
    		carstopJsonHandler =new CarStopFindStopJsonHandler();    	
    		CarStopJsonStr=carstopJsonHandler.toJSONArray(carstoplist).toString();
		}
    	

		
	       rp.setContentType("text/html; charset=utf-8");
	        PrintWriter out = rp.getWriter();
	        out.println(CarStopJsonStr); 
	        out.close();

	}
    	
}